<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>字典明细管理</title>
    <#-- 使用相对当前模板文件的路径 再去找另一个模板文件 -->
    <#include "/common/link.ftl">


</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--定义一个变量  菜单回显-->
    <#assign currentMenu="systemDictionaryItem"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>字典明细管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <div class="row" style="margin:20px">
                    <div class="col-xs-2">
                        <div class="panel panel-default">
                            <div class="panel-heading">字典目录</div>
                            <div class="panel-body">
                                <div class="list-group" id="dic">
                                    <#list systemDictionaries as tmp>
                                        <a onclick="typeClick(${tmp.id})" href="javascript:;"
                                           class="list-group-item itemtype <#if tmp.id == qo.typeId>active</#if>">${tmp.title}</a>
                                    </#list>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-10">
                        <!--高级查询--->
                        <form class="form-inline" id="searchForm" action="/systemDictionaryItem/list" method="post">
                            <input type="hidden" name="currentPage" id="currentPage" value="1">
                            <input type="hidden" name="typeId" id="typeId" value="${qo.typeId}">
                            <a href="javascript:;" onclick="addBtn()" class="btn btn-success btn-input"
                               style="margin: 10px">
                                <span class="glyphicon glyphicon-plus"></span> 添加
                            </a>
                        </form>
                        <!--编写内容-->
                        <div class="box-body table-responsive no-padding ">
                            <table class="table table-hover table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>字典明细标题</th>
                                    <th>字典明细序号</th>
                                    <th>上级明细</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <#list result.list as tmp>
                                    <tr>
                                        <td>1</td>
                                        <td>
                                            <a href="#">${tmp.title}</a>
                                        </td>
                                        <td>${tmp.sequence}</td>
                                        <td>${tmp.parentTitle}</td>
                                        <td>
                                            <a href="javascript:;" data-json='${tmp.json}'
                                               class="editBtn btn btn-info btn-xs btn-input ">
                                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                                            </a>
                                        </td>
                                    </tr>
                                </#list>
                                </tbody>

                            </table>
                            <#include "/common/page.ftl" >
                        </div>
                    </div>
                </div>

            </div>
        </section>
    </div>
    <#include "/common/footer.ftl" >
</div>


<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <form class="form-horizontal" action="/systemDictionaryItem/saveOrUpdate" method="post" id="editForm">
                <div class="modal-body">
                    <input type="hidden" name="id" id="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">字典目录：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="typeId" id="type_id">
                                <#list systemDictionaries as tmp>
                                    <option value="${tmp.id}">${tmp.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">上级明细：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="parentId" id="parentId">
                                <option value="">无</option>
                                <#list systemDictionaryItems as tmp>
                                    <option value="${tmp.id}">${tmp.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">明细标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title" id="title"
                                   placeholder="请输入字典明细编码">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">明细序号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sequence" id="sequence"
                                   placeholder="请输入字典明细序号">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary btn-submit" onclick="saveBtn()">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    function typeClick(typeId) {
        $("#typeId").val(typeId);
        $("#searchForm").submit();
    }

    function addBtn() {
        var type_id = $("#typeId").val();
        if(type_id.length !=0){
            $("#type_id").val(type_id)
        }
        $("#editModal").modal("show");
    }

    function saveBtn() {
        $("#editForm").submit();
    }

    $(".editBtn").click(function () {
        var json = $(this).data("json")

        $("#id").val(json.id)
        $("#title").val(json.title)
        $("#sequence").val(json.sequence)
        $("#parentId").val(json.parentId)

        $("#type_id").val(json.typeId)

        $("#editModal").modal("show");
    })

</script>
</body>
</html>
